{% extends "base.html" %}

{% block title %}{% if user %}编辑用户{% else %}添加用户{% endif %} - 妙趣拾光锦盒管理系统{% endblock %}

{% block content %}
<div class="row">
    <div class="col-12 mb-4">
        <h2 class="border-bottom pb-2">
            <i class="fas {% if user %}fa-user-edit{% else %}fa-user-plus{% endif %} me-2"></i>
            {% if user %}编辑用户{% else %}添加用户{% endif %}
        </h2>
    </div>
</div>

<div class="row">
    <div class="col-md-8">
        <div class="card shadow-sm">
            <div class="card-body">
                <form method="POST" novalidate>
                    <div class="mb-3">
                        <label for="username" class="form-label">用户名 <span class="text-danger">*</span></label>
                        <input type="text" class="form-control" id="username" name="username" required value="{{ user.username if user else '' }}">
                    </div>
                    
                    {% if not user %}
                    <div class="mb-3">
                        <label for="password" class="form-label">密码 <span class="text-danger">*</span></label>
                        <input type="password" class="form-control" id="password" name="password" required>
                    </div>
                    
                    <div class="mb-3">
                        <label for="confirm_password" class="form-label">确认密码 <span class="text-danger">*</span></label>
                        <input type="password" class="form-control" id="confirm_password" name="confirm_password" required>
                    </div>
                    {% endif %}
                    
                    <div class="mb-3">
                        <label for="full_name" class="form-label">姓名</label>
                        <input type="text" class="form-control" id="full_name" name="full_name" value="{{ user.full_name if user else '' }}">
                    </div>
                    
                    <div class="mb-3">
                        <label for="email" class="form-label">邮箱</label>
                        <input type="email" class="form-control" id="email" name="email" value="{{ user.email if user else '' }}">
                    </div>
                    
                    <div class="mb-3">
                        <label for="phone" class="form-label">电话</label>
                        <input type="text" class="form-control" id="phone" name="phone" value="{{ user.phone if user else '' }}">
                    </div>
                    
                    <div class="mb-3">
                        <label class="form-label">管理员权限</label>
                        <div class="form-check form-switch">
                            <input class="form-check-input" type="checkbox" id="is_admin" name="is_admin" value="1" {% if user and user.is_admin %}checked{% endif %}>
                            <label class="form-check-label" for="is_admin">赋予用户管理系统的权限</label>
                        </div>
                    </div>
                    
                    <div class="d-grid gap-2 d-md-flex justify-content-md-end mt-4">
                        <a href="{{ url_for('user.list') }}" class="btn btn-secondary me-md-2">
                            <i class="fas fa-times me-1"></i>取消
                        </a>
                        <button type="submit" class="btn btn-primary">
                            <i class="fas fa-save me-1"></i>保存
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    
    <div class="col-md-4">
        <div class="card shadow-sm">
            <div class="card-header bg-light">
                <h5 class="mb-0"><i class="fas fa-info-circle me-2"></i>提示信息</h5>
            </div>
            <div class="card-body">
                <p><strong>用户名：</strong>必填，用户登录系统的唯一标识</p>
                <p><strong>密码：</strong>必填，设置用户的登录密码</p>
                <p><strong>姓名：</strong>可选，用户真实姓名</p>
                <p><strong>邮箱：</strong>可选，用于接收系统通知等</p>
                <p><strong>电话：</strong>可选，用户联系方式</p>
                <p><strong>状态：</strong>用户账号状态，禁用的用户将无法登录系统</p>
                <p><strong>管理员权限：</strong>赋予用户管理系统的权限</p>
            </div>
        </div>
    </div>
</div>
{% endblock %}
